using Firestarter.DB.Schema.BO;
using Firestarter.DB.Schema.Test.Logic;
using FireStarterModeller.Test;
using Habanero.DB;
using Habanero.Testability;
using NUnit.Framework;

namespace Firestarter.DB.Schema.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DatabaseConnectionInfo objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DatabaseConnectionInfo.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDatabaseConnectionInfo
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }
        [Test]
        public void Test_CreateDatabaseConfig()
        {
            //---------------Set up test pack-------------------
            DatabaseConnectionInfo databaseConnectionInfo = new DatabaseConnectionInfo
            {
                Vendor = GetRandomString(),
                Server = GetRandomString(),
                Database = GetRandomString(),
                UserName = GetRandomString(),
                Password = GetRandomString()
            };
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            DatabaseConfig databaseConfig = databaseConnectionInfo.CreateDatabaseConfig();
            //---------------Test Result -----------------------
            Assert.IsNotNull(databaseConfig);
            Assert.AreEqual(databaseConnectionInfo.Vendor, databaseConfig.Vendor);
            Assert.AreEqual(databaseConnectionInfo.Server, databaseConfig.Server);
            Assert.AreEqual(databaseConnectionInfo.Database, databaseConfig.Database);
            Assert.AreEqual(databaseConnectionInfo.UserName, databaseConfig.UserName);
            Assert.AreEqual(databaseConnectionInfo.Password, databaseConfig.Password);
        }

        private string GetRandomString()
        {
            return RandomValueGen.GetRandomString();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DatabaseConnectionInfo connectionInfo =
                TestUtilsDatabaseConnectionInfo.CreateUnsavedValidDatabaseConnectionInfo();
            //---------------Assert Precondition----------------
            Assert.IsFalse(string.IsNullOrEmpty(connectionInfo.Vendor), "Vendor Should Not b null");
            //---------------Execute Test ----------------------
            string actualToString = connectionInfo.ToString();
            //---------------Test Result -----------------------
            string expectedToString = connectionInfo.Vendor + "-" + connectionInfo.Server + "-" + connectionInfo.Database + "-" + connectionInfo.UserName;
            Assert.AreEqual(expectedToString, actualToString);
        }

        [Test]
        public void Test_Parent_ReturnsNull()
        {
            //---------------Set up test pack-------------------
            DatabaseConnectionInfo connectionInfo =
                TestUtilsDatabaseConnectionInfo.CreateUnsavedValidDatabaseConnectionInfo();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------

            //---------------Test Result -----------------------
            Assert.IsNull(connectionInfo.Parent);
        }
    }
}